home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Enciclopedia Del Perro
/
Enciclopedia Del Perro.iso
/
i-view
/
ivpro163.zip
/
CGI.ZIP
/
TESTCGI.C
next >
Wrap
C/C++ Source or Header
|
1996-06-12
|
3KB
|
90 lines
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "windows.h"
// Simple back-end Windows CGI test program.
// This program is used as WIN CGI back-end program for I-View or other
// client applications who support WIN CGI. It's command line must follow
// the following convension:
//
// Command line format:
// argv[0] -- path of this back-end executable.
// argv[1] -- path of the CGI data file.
// argv[2] -- path to the file containing any content the was received
// with the client(I-View)'s request, regardless of the method.
// argv[3] -- path of the output file where this back-end execuble puts
// results.
// argv[4] -- anything that follows an unescaped "?" in the requested URL.
//
// This is just a test program. It gets information from the command line
// arguments, reads data from the CGI data file, then writes the result to
// the output file from which the client application (such as I-View) will
// read.
//
//
main(argc, argv)
int argc;
char **argv;
{
char cgi_data_file[128];
char content_file[128];
char output_file[128];
char url_args[128];
char temp[256];
FILE *fp1, *fp2;
// check if number of arguments is correct
if (argc != 5)
return 0;
// get command line arguments
strcpy(cgi_data_file, argv[1]);
strcpy(content_file, argv[2]);
strcpy(output_file, argv[3]);
strcpy(url_args, argv[4]);
// We now allow empty data file
// open CGI data file for read
//if (!(fp1 = fopen(cgi_data_file, "r")))
// return 0;
fp1 = fopen(cgi_data_file, "r");
// open output file for write
if (!(fp2 = fopen(output_file, "w")))
{
fclose(fp1);
return 0;
}
// write HTML header stuff to output file
fprintf(fp2, "<HTML>\n<HEAD>\n<TITLE>Window CGI Test Results</TITLE>\n</HEAD>\n<BODY>\n");
// write command line info to output file:
fprintf(fp2, "<H3>Your Command Line Information</H3>\n");
fprintf(fp2, "<UL>\n<LI><I>CGI Data File is</I>: %s</LI>\n", cgi_data_file);
fprintf(fp2, "<LI><I>Content File is</I>: %s</LI>\n", content_file);
fprintf(fp2, "<LI><I>Output File is</I>: %s</LI>\n", output_file);
fprintf(fp2, "<LI><I>URL arguments are</I>: %s</LI>\n</UL>\n<HR>\n", url_args);
// here we just copy contents of CGI data file to the output file.
// in real WIN CGI back-end program, we may need to do some work
// on the input cgi data buffer, then write results to the output
// file.
fprintf(fp2, "<H3>Content of Your CGI Data File</H3>\n");
fprintf(fp2, "<PRE>\n");
while (fp1 && fgets(temp, 256, fp1))
{
fprintf(fp2, "%s", temp);
}
fprintf(fp2, "</PRE><HR>\n");
// write HTML stuff
fprintf(fp2, "</BODY>\n</HTML>\n\n");
fclose(fp2);
return 1;
}